/*
Copyright (C) 2015 Marien Raat

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <SFML/Graphics.hpp>
#include <islandHeightmapGenerator.h>
#include <mapDisplay.h>
#include <markovNames.h>
#include <landMap.h>
#include <waterGenerator.h>
#include <lightingGenerator.h>
#include <biomeGenerator.h>

#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__)
#define OS_WIN
#endif

class SFMLFrontend {
public:
    SFMLFrontend(unsigned screenSizeX, unsigned screenSizeY);
    void start();
private:
    sf::Vector2u screenSize;
    sf::RenderWindow *window;

#ifndef OS_WIN
    std::random_device *randomDevice;
#endif
    std::mt19937 *mt;

    sf::Font islandNameFont;

    bool focus;

    // Whether to use the mouse as lamp or the sun in the relief (4)
    // mode.
    bool useMouseLamp;
    // The height of the mouse lamp
    double mouseLampHeight;

    double waterLevel;
    double *heightmapModifiers;
    IslandHeightmapGenerator *islandHeightmapGenerator;
    MapDisplayer *mapDisplayer;
    MarkovNames *markovNames;
    LandMapGenerator *landMapGenerator;
    WaterSettings waterSettings;
    WaterGenerator *waterGenerator;
    LightingGenerator *lightingGenerator;
    BiomeGenerator *biomeGenerator;

    void loadFiles();

    void handleEvents();
    void handleInput();
    void update();
    void draw();

    void updateHeightmapDisplay();

    double *getClippedHeightmap(double clipValue);
};
